package com.yyyzzz.servlet;

import com.yyyzzz.bean.Course;
import com.yyyzzz.service.courseService;
import com.yyyzzz.service.impl.courseServiceimpl;
import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/updateCourseServlet")
public class updateCourseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String courseId = request.getParameter("courseId");
        String coursename = request.getParameter("courseName");
        String courseteacher = request.getParameter("courseTeacher");
        String classroom = request.getParameter("classroom");
        Double credit = Double.parseDouble(request.getParameter("credit"));
        response.setCharacterEncoding("utf-8");


        Course course = new Course();
        course.setCourseId(courseId);
        course.setCourseName(coursename);
        course.setCourseTeacher(courseteacher);
        course.setClassroom(classroom);
        course.setCredit(credit);
        courseServiceimpl service = new courseServiceimpl();
        boolean update = service.updateCourse(course);
        if(update==true){
            request.getRequestDispatcher("courseDetail.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("updateError.jsp").forward(request,response);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
